import Vue from 'vue'
import Router from 'vue-router'
import Cookies from 'js-cookie'
Vue.use(Router)

import Layout from '@/layout'
let userType = null;
let hidden = true;

if(Cookies.get("user"))
{
  userType = JSON.parse(Cookies.get("user"))?.userType|| null;


}

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard',  }
    }]

  },

  {
    path: '/company',
    component: Layout,
    redirect: '/company',
    name: 'Company',
    meta: { title: '招聘求职', icon: 'el-icon-s-cooperation' },
    children: [
      {
        path: 'companyList',
        name: 'CompanyList',
        meta: { title: '企业信息', icon: 'el-icon-s-platform' },
        component: () => import('@/views/company/index')
      },
      {
        path: 'position',
        name: 'Position',
        meta: { title: '职位审核', icon: 'el-icon-tickets' },
        component: () => import('@/views/company/position')
      },
      {
        path: 'personnel',
        name: 'Personnel',
        meta: { title: '招聘人员审核', icon: 'el-icon-user-solid' },
        component: () => import('@/views/personnel/index')
      },
      {
        path: 'customerList',
        name: 'CustomerList',
        meta: { title: '求职人员列表', icon: 'el-icon-s-custom' },
        component: () => import('@/views/customer/index')
      },
      {
        path: 'jobFairs',
        name: 'JobFairs',
        meta: { title: '招聘会列表', icon: 'el-icon-office-building' },
        component: () => import('@/views/jobFairs/index')
      },
      {
        path: 'livePortend',
        name: 'LivePortend',
        meta: { title: '直播预告', icon: 'el-icon-video-camera' },
        component: () => import('@/views/livePortend/index')
      },
      {
        path: 'jobFairsCom',
        name: 'JobFairsCom',
        meta: { title: '参会企业',activeMenu: `/jobFairs/jobFairsCom` },
        hidden: true,
        component: () => import('@/views/jobFairs/scanRecord')
      },

      {
        path: 'jobFairsPublish',
        name: 'JobFairsComPublish',
        meta: { title: '参会岗位',activeMenu: `/jobFairs/jobFairsPublish` },
        hidden: true,
        component: () => import('@/views/jobFairs/jobFairsPublish')
      }
    ],
  },
  {
    path: '/article-code',
    component: Layout,
    name: 'PlaceCode',
    children: [
      {
        path: 'article',
        name: 'article',
        meta: { title: '文章管理', icon: 'el-icon-s-grid' },
        component: () => import('@/views/article-code/index')
      }
    ],
  },
  {
    path: '/train',
    component: Layout,
    redirect: '/train',
    name: 'Train',
    meta: { title: '技能培训管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'trainList',
        name: 'TrainList',
        meta: { title: '技能培训', icon: 'el-icon-medal-1' },
        component: () => import('@/views/train/index')
      },

      {
        path: 'trainCustomer',
        name: 'TrainCustomer',
        meta: { title: '报名列表',activeMenu: `/train/trainCustomer` },
        hidden: true,
        component: () => import('@/views/train/trainCustomer')
      }

    ],

  },
  {
    path: '/entrepreneurship_expert',
    component: Layout,
    redirect: '/entrepreneurship_expert',
    name: 'Entrepreneurship_expert',
    meta: { title: '青年见习', icon: 'el-icon-s-shop' },
    children: [
      {
        path: 'entrepreneurship',
        name: 'Entrepreneurship',
        meta: { title: '青年见习', icon: 'el-icon-coordinate' },
        component: () => import('@/views/entrepreneurship/index')
      },


    ],
  },
  {
    path: '/report',
    component: Layout,
    redirect: '/report',
    name: 'Train',
    meta: { title: '运营管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'reportList',
        name: 'ReportList',
        meta: { title: '举报信息管理', icon: 'el-icon-info' },
        component: () => import('@/views/report/index')
      },
      {
        path: 'advertisement',
        name: 'Advertisement',
        meta: { title: '广告管理', icon: 'el-icon-s-opportunity' },
        component: () => import('@/views/advertisement/index')
      },

    ],

  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
